package com.bnzj.cloud.business.core.persistence.entity;

import com.bnzj.core.persistence.entity.BaseEntity;
import com.fasterxml.jackson.annotation.JsonBackReference;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.persistence.*;

@Getter
@Setter
@ToString(exclude = {"role", "resource"}, callSuper = true)
@Entity
@Table(name = "bnz_sys_role_resource")
@Schema(description = "角色与资源的关系")
public class SysRoleResource extends BaseEntity {
    private static final long serialVersionUID = 8113968294390361466L;
    private Long roleId;
    private Long resourceId;

    // JoinColumn，注释本表中指向另一个表的外键
    @JoinColumn(name = "roleId", insertable = false, updatable = false)
    @OneToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
    @JsonBackReference("relation-role-resource")
    private SysRole role;

    // JoinColumn，注释本表中指向另一个表的外键
    @JoinColumn(name = "resourceId", insertable = false, updatable = false)
    @OneToOne(cascade = {CascadeType.REFRESH}, fetch = FetchType.LAZY)
    @JsonBackReference("resource")
    private SysResource resource;
}
